﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Description;
using Services;

namespace Host
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host1 = null, host2 = null;
            try
            {
                host1 = OpenHost(typeof(ChartResultsService), typeof(IChartResultsService), "net.pipe://localhost/ChartResultsService");
                host2 = OpenHost(typeof(NewsResultsService), typeof(INewsResultsService), "net.pipe://localhost/NewsResultsService");

                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();
            }
            finally
            {
                if(host1 !=null) host1.Close();
                if(host2 !=null)host2.Close();
            }
        }

        static private ServiceHost OpenHost(Type type, Type intrface, string address)
        {
            var host = new ServiceHost(type, new Uri(address));

            host.Description.Endpoints.Clear();
            host.AddServiceEndpoint(intrface, new NetNamedPipeBinding(), address);
            host.Open();

            return host;
        }
    }
}
